﻿@model EvinceUI.Models.LogOnModel
@{
    Layout = "~/Views/Shared/_Layout_Login.cshtml";
    ViewBag.Title = "Log On";
    

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#forgotyourpass').hide();
        $('#fgtemailErrorId').hide();
        $('#sendbtn').click(function () {
            var email = $('#txtfgtEmailId').val();
            if (email != '') {
                $.ajax({
                    type: "POST",
                    url: "/Login/AuthenticateEmailId?emailId=" + email,
                    success: function (success) {
                        if (success.result == true) {
                            $('#emailMessageId').html('Your password is sent to your email!');
                            $('#emailMessageId').css({ 'color': 'green' });
                            $('#emailMessageId').show();
                        }
                        else {
                            $('#emailMessageId').html('Email Id provided by you is invalid!');
                            $('#emailMessageId').css({ 'color': 'red' });
                            $('#emailMessageId').show();
                        }

                    }
                });
            }
            else {
                $('#fgtemailErrorId').show();
            }
            //window.location = "/Login/AuthenticateEmail";
            return false;



        });

        $('#fgtPassword').click(function () {

            $('#login').hide();
            $('#forgotyourpass').show();
            //window.location = "/Login/AuthenticateEmail";
            return false;



        });
        $('#bktoLogin').click(function () {
            $('#login').show();
            $('#forgotyourpass').hide();




        });
        $('#registerNewUser').click(function () {
            window.location = "/Account/Register";
        });
        $('#loginFailedId').hide();
        $('#emailErrorId').hide();
        $('#passwordErrorId').hide();
        $('#btnCancel').click(function () {
            $('#txtEmailId').val('');
            $('#txtPasswordId').val('');
            return false;
        });
        var info1 = $('#loginStatus').val();
        if (info1 == 'Login failed') {
            $('#loginFailedId').show();
        }
        $('#fgtPassword').click(function () {
            ('#login').hide();
            ('#forgotyourpass').show();



        });


    });

</script>
    var loginStatus = ViewBag.ErrorMessage as string;
<input type="hidden" value="@loginStatus" id="loginStatus" />
    using (@Html.BeginForm("Login", "Account", FormMethod.Post, new { id = "validate" }))
{   
<div class="grid_5 login" >
         <div class="box round">
         <h2>Login</h2>
           <table class="form" id="login">
                <tr>
                    <td align="right" width="30%" style="padding-right: 20px;">
                        <label>
                            E-mail
                        </label>
                    </td>
                    <td align="left" width="70%">
                         @Html.TextBoxFor(m => m.UserName)
                       @* <input type="text" name="emailId" id="txtEmailId" style="width: 200px;" />*@
                        <span class="error" id="emailErrorId">*</span>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="30%" style="padding-right: 20px;">
                        <label>
                            Password
                        </label>
                    </td>
                    <td align="left" width="70%">
                      @*  <input type="password" name="password" id="txtPasswordId" style="width: 200px;" />*@
                      @Html.TextBoxFor(m => m.Password, new {type="password" })
                        <span class="error" id="passwordErrorId">*</span>
                    </td>
                </tr>
                <tr>
                    <td align="right" width="30%" style="padding-right: 20px;">
                        <div class="block">
                            @*<input type="button" runat="server" class="btn btn-orange" value="Login" />*@
                            <button class="btn btn-orange" id="loginBtn">
                                Login</button>
                        </div>
                    </td>
                    <td align="left" width="30%" style="padding-left: 20px;">
                        <div class="block">
                            <button class="btn btn-orange" id="btnCancel">
                                Cancel</button>
                        </div>
                    </td>
                </tr>
                 <tr align="center">
                    <td colspan="2">
                        <a href="#" id="registerNewUser">New user? Register here!</a>
                    </td>
                </tr>
                <tr align="center">
                    <td colspan="2">
                        <a href="#" id="fgtPassword">Forget Your Password</a>
                    </td>
                </tr>
               
            </table>
            <table class="form"  id="forgotyourpass">
             <tr>
                    <td align="center" width="30%" style="padding-right: 20px;">
                        <label>
                            E-Mail <input type="text" name="emailId" id="txtfgtEmailId" style="width: 200px;" />
                        <span class="error" id="fgtemailErrorId">*</span>
                        </label>
                    </td>
                   
                </tr>
                <tr>
               
                <td align="center" width="30%" style="padding-right: 20px;">
                            <button class="btn btn-orange" id="sendbtn">
                                Send </button>
                    </td>
                    
                </tr>
                <tr>
                 <td align="center" width="30%" style="padding-right: 20px;">
                         <label id="emailMessageId" style="display:none; color:Green;"></label>
                    </td>
                </tr>
                <tr align="center">
                    <td >
                        <a href="#" id="bktoLogin">Back To Login</a>
                    </td>
                </tr>
            </table>
        @*<fieldset>
            <h2>Login</h2>

            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>

            <p>
                <input type="submit" class="btn btn-orange" value="Log On" />
            </p>
        </fieldset>*@
        <label style="color:Red;"> @Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")</label>
        </div>
    </div>
}
    }